﻿#region Copyright (C) Sector7 Software Studio. All rights reserved
/*******************************************************************************************
 * Creation
 *      Author:         Wolf Lai
 *      Date:           2012/4/23 17:14:51
 *      Version:        
 * Modification 
 *      Author: 
 *      Date: 
 *      Description: 
 *      Version:
 *******************************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sector7.Restaurant.EntityType;
using Sector7.Framework.Core;
using System.Data.SqlClient;
using Sector7.Framework.DB;

namespace Sector7.Restaurant.DAO.OleDB
{
    /// <summary>
    /// 库存数据访问对象
    /// </summary>
    public class StockDAO : IStockDAO
    {
        #region Public functions
        public List<RS_Stock> ReadAll(int typeId)
        {
            using (DBHelper opt = new DBHelper())
            {
                List<RS_Stock> stocks = new List<RS_Stock>();

                string sql =
                    "SELECT\n" +
                    "\t*\n" +
                    "FROM\n" +
                    "\tRS_Stock stock\n" +
                    "LEFT JOIN\n" +
                    "\tRS_MetaData metaData ON metaData.Id = stock.MetaDataId\n" +
                    "LEFT JOIN\n" +
                    "\tRS_MetaDataType metaDataType ON metaDataType.TypeId = metaData.TypeId\n" +
                    ""+
                    ""+
                    ""+
                    ""+
                    "WHERE\n" +
                    "\tmetaDataType.TypeId = @TypeId" +
                    "" +
                    "" +
                    "" +
                    "" +
                    "" +
                    "";

                SqlDataReader reader = opt.ExecuteQuery(
                    sql,
                    DBUtil.CreateSqlParameter(typeId, "TypeId"));

                while (reader.Read())
                {
                    object stock = new RS_Stock();

                    DBUtil.ReadData(reader, ref stock);

                    stocks.Add(stock as RS_Stock);
                }

                return stocks;
            }
        }
        #endregion
    }
}
